<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>

        /*  
            继承
                - 通过继承可以在不修改一个类的情况下对其扩展
                - OCP 开闭原则
                    -程序应该对修改关闭,对扩展开放
        */
            class Animal{
                constructor(name){
                    this.name = name
                }
                sayHello(){
                    console.log("动物");
                }
            }
            class Dog extends Animal{
                constructor(name,age){
                    super(name)
                    this.age = age
                }
            }
            class Cat extends Animal{
                sayHello(){
                    console.log("喵喵喵");
                }            
            }

            const dog = new Dog("狗",22)
            const cat = new Cat("猫")
            console.log(dog);
            console.log(cat);
            cat.sayHello()
            dog.sayHello()
            
        
    </script>
</head>
<body>
    
</body>
</html>